﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Uaf.Core.Commands
{
	public abstract class UICommand: INotifyPropertyChanged
	{
		#region Separator

		private class SeparatorCommand : UICommand
		{
			public SeparatorCommand()
			{
				Text = "-";
			}

			public override void Execute(object argument)
			{
				throw new NotImplementedException();
			}
		}

		public static readonly UICommand Separator = new SeparatorCommand();

		#endregion

		#region Properties

		public string Id
		{
			get;
			protected set;
		}

		private string _text;
		public virtual string Text 
		{
			get { return _text; }
			set
			{
				if (_text != value)
				{
					_text = value;
					OnPropertyChanged("Text");
				}
			}
		}

		private object _image;
		public virtual object Image
		{
			get { return _image; }
			set
			{
				if (_text != value)
				{
					_image = value;
					OnPropertyChanged("Image");
				}
			}
		}

		private string _description;
		public virtual string Description
		{
			get { return _description; }
			set
			{
				if (_description != value)
				{
					_description = value;
					OnPropertyChanged("Description");
				}
			}
		}

		private bool? _isChecked;
		public virtual bool? IsChecked
		{
			get { return _isChecked; }
			set
			{
				if (_isChecked != value)
				{
					_isChecked = value;
					OnPropertyChanged("IsChecked");
				}
			}
		}

		private bool _isEnabled;
		public bool IsEnabled
		{
			get { return _isEnabled; }
			set
			{
				if (_isEnabled != value)
				{
					_isEnabled = value;
					OnPropertyChanged("IsEnabled");
				}
			}
		}

		private bool _isVisible;
		public bool IsVisible
		{
			get { return _isVisible; }
			set
			{
				if (_isVisible != value)
				{
					_isVisible = value;
					OnPropertyChanged("IsVisible");
				}
			}
		}

		public ICollection<UICommand> Children 
		{ 
			get; 
			private set;
		}

		#endregion

		protected UICommand()
		{
			Children = new List<UICommand>();
		}

		public void Execute()
		{
			Execute(null);
		}

		public abstract void Execute(object argument);

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;
		protected void OnPropertyChanged(string name)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(name));
		}

		#endregion
	}
}
